package com.hpin.fansea.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hpin.fansea.R;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by Aaron on 15/9/16.
 */
public class CircleWatefullAdaper extends RecyclerView.Adapter<CircleWatefullAdaper.ViewHolder> implements View.OnClickListener  {

//    private List<StoreContent> data;//填充数据的集合
    protected ImageLoader imageLoader = ImageLoader.getInstance();//采用universal imageloader来加载图片

    public CircleWatefullAdaper() {
    }

//    public CircleWatefullAdaper(List<StoreContent> data) {
//        this.data = data;
//    }

//    public void setData(List<StoreContent> data) {
//        this.data = data;
//    }

    @Override
    public CircleWatefullAdaper.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {

        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_circle_waterfull, viewGroup, false);
        ViewHolder vh = new ViewHolder(view);
        view.setOnClickListener(this);
        return vh;

    }

    @Override
    public void onBindViewHolder(final CircleWatefullAdaper.ViewHolder viewHolder, final int i) {

//        viewHolder.itemView.setTag(data.get(i));
//        viewHolder.iv_show.setImageResource(R.drawable.whitebottom);
//        viewHolder.iv_show.setTag(data.get(i).getCoverUrl());
//        ImageSize imageSize = new ImageSize(150, 200);
//        imageLoader.loadImage(data.get(i).getCoverUrl(), imageSize, new ImageLoadingListener() {
//            @Override
//            public void onLoadingStarted(String s, View view) {
//
//            }
//
//            @Override
//            public void onLoadingFailed(String s, View view, FailReason failReason) {
//
//            }
//
//            @Override
//            public void onLoadingComplete(String imgUrl, View view, Bitmap bitmap) {
//                if (viewHolder.iv_show.getTag() != null && viewHolder.iv_show.getTag().equals(imgUrl)) {
//                    //此处代码获取屏幕的宽高，实现不同屏幕的适配
//                    int width = BaseApplication.getWindowWidth() / 2;
//                    int height = width * bitmap.getHeight() / bitmap.getWidth();//高通过宽等比例缩放
//                    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
//                            width, height);
//                    viewHolder.iv_show.setLayoutParams(params);
//                    viewHolder.iv_show.setImageBitmap(bitmap);
//
////                    viewHolder.tv_date.setText("总销"
////                            + data.get(i).getSale() + "件");
////                    viewHolder.tv_price.setText("¥ "
////                            + CommonUtils.getShortPrice(
////                            data.get(i).getSalePrice(),
////                            2));
//                }
//            }
//
//            @Override
//            public void onLoadingCancelled(String s, View view) {
//
//            }
//        });
    }

    @Override
    public int getItemCount() {
        return 4;
    }

    @Override
    public void onClick(View v) {
        if (null != mOnItemClickListener) {
//            mOnItemClickListener.onClick(v, (StoreContent) v.getTag());
        }
    }

    //创建一个viewholder类
    public static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView iv_show;
        TextView tv_style;
        TextView tv_green;
        TextView tv_first;
        TextView tv_old_price;
        TextView tv_now_price;

        public ViewHolder(View itemView) {
            super(itemView);
            iv_show = (ImageView) itemView.findViewById(R.id.iv_show);
            tv_style = (TextView) itemView.findViewById(R.id.tv_style);
            tv_green = (TextView) itemView.findViewById(R.id.tv_green);
            tv_first = (TextView) itemView.findViewById(R.id.tv_first);
            tv_old_price = (TextView) itemView.findViewById(R.id.tv_old_price);
            tv_now_price = (TextView) itemView.findViewById(R.id.tv_now_price);
        }
    }

    private OnRecyclerViewItemClickListener mOnItemClickListener = null;

    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }

    public static interface OnRecyclerViewItemClickListener {
//        void onClick(View view, StoreContent itemData);
    }

}
